package com.wqtz.chechai.view.fragments;

import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.wqtz.chechai.R;
import com.wqtz.chechai.base.BaseFragment;
import com.wqtz.chechai.presenter.BasePresent;
import com.wqtz.chechai.utils.ToastUtils;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2016/12/12 13:35
 */

public class ToolsFragment extends BaseFragment {


	@BindView(R.id.iv_back)
	ImageView mIvBack;
	@BindView(R.id.tv_title)
	TextView mTvTitle;
	@BindView(R.id.gview)
	GridView gridview;
	ArrayList<HashMap<String, Object>> lstImageItem;

	// 图片封装为一个数组
	private int[] icon = {R.drawable.tool_xinshou, R.drawable.tool_quickgetpay,
			R.drawable.tool_shenhetiaojian, R.drawable.tool_payback, R.drawable.tool_safe,
			R.drawable.tool_vin, R.drawable.tool_calculate, R.drawable.tool_weizhang,
			R.drawable.tool_assume};
	private String[] iconName = {"新手指南", "快速下款", "审核条件", "还款", "安全", "VIN码查询", "汇率计算",
			"违章查询", "估价"};

	@Override
	public BasePresent createPresenter() {
		return null;
	}

	@Override
	protected int getContentView() {
		return R.layout.fragment_tools;
	}

	@Override
	protected void init(View view) {
		ButterKnife.bind(this, view);

	}

	@Override
	protected void loadDatas() {
		lstImageItem = new ArrayList<>();
		for (int i = 0; i < icon.length; i++) {
			HashMap<String, Object> map = new HashMap<>();
			map.put("ItemImage", icon[i]);//添加图像资源的ID
			map.put("ItemText", iconName[i]);//按序号做ItemText
			lstImageItem.add(map);
		}
		//生成适配器的ImageItem <====> 动态数组的元素，两者一一对应
		SimpleAdapter saImageItems = new SimpleAdapter(getContext(), //没什么解释
				lstImageItem,
				R.layout.item_tool,
				new String[]{"ItemImage", "ItemText"},
				new int[]{R.id.ItemImage, R.id.ItemText});
		        gridview.setAdapter(saImageItems);
	            gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
		          @Override
		          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			          ToastUtils.show(getContext(),iconName[position],1000);

		          }
	          });
	}

}


